/**
 * @remix-run/router v1.1.0
 *
 * Copyright (c) Remix Software Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.md file in the root directory of this source tree.
 *
 * @license MIT
 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RemixRouter={})}(this,(function(e){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},t.apply(this,arguments)}var r;e.Action=void 0,(r=e.Action||(e.Action={})).Pop="POP",r.Push="PUSH",r.Replace="REPLACE";const a="popstate";function n(e,t){if(!1===e||null==e)throw new Error(t)}function o(e,t){if(!e){"undefined"!=typeof console&&console.warn(t);try{throw new Error(t)}catch(e){}}}function i(e){return{usr:e.state,key:e.key}}function s(e,r,a,n){return void 0===a&&(a=null),t({pathname:"string"==typeof e?e:e.pathname,search:"",hash:""},"string"==typeof r?d(r):r,{state:a,key:r&&r.key||n||Math.random().toString(36).substr(2,8)})}function l(e){let{pathname:t="/",search:r="",hash:a=""}=e;return r&&"?"!==r&&(t+="?"===r.charAt(0)?r:"?"+r),a&&"#"!==a&&(t+="#"===a.charAt(0)?a:"#"+a),t}function d(e){let t={};if(e){let r=e.indexOf("#");r>=0&&(t.hash=e.substr(r),e=e.substr(0,r));let a=e.indexOf("?");a>=0&&(t.search=e.substr(a),e=e.substr(0,a)),e&&(t.pathname=e)}return t}function c(e){let t="undefined"!=typeof window&&void 0!==window.location&&"null"!==window.location.origin?window.location.origin:window.location.href,r="string"==typeof e?e:l(e);return n(t,"No window.location.(origin|href) available to create URL for href: "+r),new URL(r,t)}function u(t,r,n,o){void 0===o&&(o={});let{window:d=document.defaultView,v5Compat:u=!1}=o,h=d.history,f=e.Action.Pop,p=null;function m(){f=e.Action.Pop,p&&p({action:f,location:g.location})}let g={get action(){return f},get location(){return t(d,h)},listen(e){if(p)throw new Error("A history only accepts one active listener");return d.addEventListener(a,m),p=e,()=>{d.removeEventListener(a,m),p=null}},createHref:e=>r(d,e),encodeLocation(e){let t=c("string"==typeof e?e:l(e));return{pathname:t.pathname,search:t.search,hash:t.hash}},push:function(t,r){f=e.Action.Push;let a=s(g.location,t,r);n&&n(a,t);let o=i(a),l=g.createHref(a);try{h.pushState(o,"",l)}catch(e){d.location.assign(l)}u&&p&&p({action:f,location:g.location})},replace:function(t,r){f=e.Action.Replace;let a=s(g.location,t,r);n&&n(a,t);let o=i(a),l=g.createHref(a);h.replaceState(o,"",l),u&&p&&p({action:f,location:g.location})},go:e=>h.go(e)};return g}let h;function f(e,r,a){return void 0===r&&(r=[]),void 0===a&&(a=new Set),e.map(((e,o)=>{let i=[...r,o],s="string"==typeof e.id?e.id:i.join("-");if(n(!0!==e.index||!e.children,"Cannot specify children on an index route"),n(!a.has(s),'Found a route id collision on id "'+s+"\".  Route id's must be globally unique within Data Router usages"),a.add(s),function(e){return!0===e.index}(e)){return t({},e,{id:s})}return t({},e,{id:s,children:e.children?f(e.children,i,a):void 0})}))}function p(e,t,r){void 0===r&&(r="/");let a=R(("string"==typeof t?d(t):t).pathname||"/",r);if(null==a)return null;let n=m(e);!function(e){e.sort(((e,t)=>e.score!==t.score?t.score-e.score:function(e,t){return e.length===t.length&&e.slice(0,-1).every(((e,r)=>e===t[r]))?e[e.length-1]-t[t.length-1]:0}(e.routesMeta.map((e=>e.childrenIndex)),t.routesMeta.map((e=>e.childrenIndex)))))}(n);let o=null;for(let e=0;null==o&&e<n.length;++e)o=b(n[e],E(a));return o}function m(e,t,r,a){void 0===t&&(t=[]),void 0===r&&(r=[]),void 0===a&&(a="");let o=(e,o,i)=>{let s={relativePath:void 0===i?e.path||"":i,caseSensitive:!0===e.caseSensitive,childrenIndex:o,route:e};s.relativePath.startsWith("/")&&(n(s.relativePath.startsWith(a),'Absolute route path "'+s.relativePath+'" nested under path "'+a+'" is not valid. An absolute child route path must start with the combined path of all its parent routes.'),s.relativePath=s.relativePath.slice(a.length));let l=x([a,s.relativePath]),d=r.concat(s);e.children&&e.children.length>0&&(n(!0!==e.index,'Index routes must not have child routes. Please remove all child routes from route path "'+l+'".'),m(e.children,t,d,l)),(null!=e.path||e.index)&&t.push({path:l,score:w(l,e.index),routesMeta:d})};return e.forEach(((e,t)=>{var r;if(""!==e.path&&null!=(r=e.path)&&r.includes("?"))for(let r of g(e.path))o(e,t,r);else o(e,t)})),t}function g(e){let t=e.split("/");if(0===t.length)return[];let[r,...a]=t,n=r.endsWith("?"),o=r.replace(/\?$/,"");if(0===a.length)return n?[o,""]:[o];let i=g(a.join("/")),s=[];return s.push(...i.map((e=>""===e?o:[o,e].join("/")))),n&&s.push(...i),s.map((t=>e.startsWith("/")&&""===t?"/":t))}!function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"}(h||(h={}));const v=/^:\w+$/,y=e=>"*"===e;function w(e,t){let r=e.split("/"),a=r.length;return r.some(y)&&(a+=-2),t&&(a+=2),r.filter((e=>!y(e))).reduce(((e,t)=>e+(v.test(t)?3:""===t?1:10)),a)}function b(e,t){let{routesMeta:r}=e,a={},n="/",o=[];for(let e=0;e<r.length;++e){let i=r[e],s=e===r.length-1,l="/"===n?t:t.slice(n.length)||"/",d=D({path:i.relativePath,caseSensitive:i.caseSensitive,end:s},l);if(!d)return null;Object.assign(a,d.params);let c=i.route;o.push({params:a,pathname:x([n,d.pathname]),pathnameBase:L(x([n,d.pathnameBase])),route:c}),"/"!==d.pathnameBase&&(n=x([n,d.pathnameBase]))}return o}function D(e,t){"string"==typeof e&&(e={path:e,caseSensitive:!1,end:!0});let[r,a]=function(e,t,r){void 0===t&&(t=!1);void 0===r&&(r=!0);A("*"===e||!e.endsWith("*")||e.endsWith("/*"),'Route path "'+e+'" will be treated as if it were "'+e.replace(/\*$/,"/*")+'" because the `*` character must always follow a `/` in the pattern. To get rid of this warning, please change the route path to "'+e.replace(/\*$/,"/*")+'".');let a=[],n="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^$?{}|()[\]]/g,"\\$&").replace(/\/:(\w+)/g,((e,t)=>(a.push(t),"/([^\\/]+)")));e.endsWith("*")?(a.push("*"),n+="*"===e||"/*"===e?"(.*)$":"(?:\\/(.+)|\\/*)$"):r?n+="\\/*$":""!==e&&"/"!==e&&(n+="(?:(?=\\/|$))");return[new RegExp(n,t?void 0:"i"),a]}(e.path,e.caseSensitive,e.end),n=t.match(r);if(!n)return null;let o=n[0],i=o.replace(/(.)\/+$/,"$1"),s=n.slice(1);return{params:a.reduce(((e,t,r)=>{if("*"===t){let e=s[r]||"";i=o.slice(0,o.length-e.length).replace(/(.)\/+$/,"$1")}return e[t]=function(e,t){try{return decodeURIComponent(e)}catch(r){return A(!1,'The value for the URL param "'+t+'" will not be decoded because the string "'+e+'" is a malformed URL segment. This is probably due to a bad percent encoding ('+r+")."),e}}(s[r]||"",t),e}),{}),pathname:o,pathnameBase:i,pattern:e}}function E(e){try{return decodeURI(e)}catch(t){return A(!1,'The URL path "'+e+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent encoding ('+t+")."),e}}function R(e,t){if("/"===t)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let r=t.endsWith("/")?t.length-1:t.length,a=e.charAt(r);return a&&"/"!==a?null:e.slice(r)||"/"}function A(e,t){if(!e){"undefined"!=typeof console&&console.warn(t);try{throw new Error(t)}catch(e){}}}function P(e,t){void 0===t&&(t="/");let{pathname:r,search:a="",hash:n=""}="string"==typeof e?d(e):e,o=r?r.startsWith("/")?r:function(e,t){let r=t.replace(/\/+$/,"").split("/");return e.split("/").forEach((e=>{".."===e?r.length>1&&r.pop():"."!==e&&r.push(e)})),r.length>1?r.join("/"):"/"}(r,t):t;return{pathname:o,search:T(a),hash:j(n)}}function M(e,t,r,a){return"Cannot include a '"+e+"' character in a manually specified `to."+t+"` field ["+JSON.stringify(a)+"].  Please separate it out to the `to."+r+'` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.'}function C(e){return e.filter(((e,t)=>0===t||e.route.path&&e.route.path.length>0))}function S(e,r,a,o){let i;void 0===o&&(o=!1),"string"==typeof e?i=d(e):(i=t({},e),n(!i.pathname||!i.pathname.includes("?"),M("?","pathname","search",i)),n(!i.pathname||!i.pathname.includes("#"),M("#","pathname","hash",i)),n(!i.search||!i.search.includes("#"),M("#","search","hash",i)));let s,l=""===e||""===i.pathname,c=l?"/":i.pathname;if(o||null==c)s=a;else{let e=r.length-1;if(c.startsWith("..")){let t=c.split("/");for(;".."===t[0];)t.shift(),e-=1;i.pathname=t.join("/")}s=e>=0?r[e]:"/"}let u=P(i,s),h=c&&"/"!==c&&c.endsWith("/"),f=(l||"."===c)&&a.endsWith("/");return u.pathname.endsWith("/")||!h&&!f||(u.pathname+="/"),u}const x=e=>e.join("/").replace(/\/\/+/g,"/"),L=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),T=e=>e&&"?"!==e?e.startsWith("?")?e:"?"+e:"",j=e=>e&&"#"!==e?e.startsWith("#")?e:"#"+e:"";class U extends Error{}class O{constructor(e){let t;this.pendingKeys=new Set,this.subscriber=void 0,n(e&&"object"==typeof e&&!Array.isArray(e),"defer() only accepts plain objects"),this.abortPromise=new Promise(((e,r)=>t=r)),this.controller=new AbortController;let r=()=>t(new U("Deferred data aborted"));this.unlistenAbortSignal=()=>this.controller.signal.removeEventListener("abort",r),this.controller.signal.addEventListener("abort",r),this.data=Object.entries(e).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:this.trackPromise(r,a)})}),{})}trackPromise(e,t){if(!(t instanceof Promise))return t;this.pendingKeys.add(e);let r=Promise.race([t,this.abortPromise]).then((t=>this.onSettle(r,e,null,t)),(t=>this.onSettle(r,e,t)));return r.catch((()=>{})),Object.defineProperty(r,"_tracked",{get:()=>!0}),r}onSettle(e,t,r,a){if(this.controller.signal.aborted&&r instanceof U)return this.unlistenAbortSignal(),Object.defineProperty(e,"_error",{get:()=>r}),Promise.reject(r);this.pendingKeys.delete(t),this.done&&this.unlistenAbortSignal();const n=this.subscriber;return r?(Object.defineProperty(e,"_error",{get:()=>r}),n&&n(!1),Promise.reject(r)):(Object.defineProperty(e,"_data",{get:()=>a}),n&&n(!1),a)}subscribe(e){this.subscriber=e}cancel(){this.controller.abort(),this.pendingKeys.forEach(((e,t)=>this.pendingKeys.delete(t)));let e=this.subscriber;e&&e(!0)}async resolveData(e){let t=!1;if(!this.done){let r=()=>this.cancel();e.addEventListener("abort",r),t=await new Promise((t=>{this.subscribe((a=>{e.removeEventListener("abort",r),(a||this.done)&&t(a)}))}))}return t}get done(){return 0===this.pendingKeys.size}get unwrappedData(){return n(null!==this.data&&this.done,"Can only unwrap data on initialized and settled deferreds"),Object.entries(this.data).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:H(a)})}),{})}}function H(e){if(!function(e){return e instanceof Promise&&!0===e._tracked}(e))return e;if(e._error)throw e._error;return e._data}class q{constructor(e,t,r,a){void 0===a&&(a=!1),this.status=e,this.statusText=t||"",this.internal=a,r instanceof Error?(this.data=r.toString(),this.error=r):this.data=r}}function _(e){return e instanceof q}const I=["post","put","patch","delete"],W=new Set(I),k=["get",...I],$=new Set(k),N=new Set([301,302,303,307,308]),B=new Set([307,308]),F={state:"idle",location:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},z={state:"idle",data:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},K=!("undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement);function Y(e,t,r){void 0===r&&(r=!1);let a,n="string"==typeof e?e:l(e);if(!t||!function(e){return null!=e&&"formData"in e}(t))return{path:n};if(t.formMethod&&!pe(t.formMethod))return{path:n,error:ie(405,{method:t.formMethod})};if(t.formData&&(a={formMethod:t.formMethod||"get",formAction:le(n),formEncType:t&&t.formEncType||"application/x-www-form-urlencoded",formData:t.formData},me(a.formMethod)))return{path:n,submission:a};let o=d(n);try{let e=ee(t.formData);r&&o.search&&ye(o.search)&&e.append("index",""),o.search="?"+e}catch(e){return{path:n,error:ie(400)}}return{path:l(o),submission:a}}function J(e,t){let r=e;if(t){let a=e.findIndex((e=>e.route.id===t));a>=0&&(r=e.slice(0,a))}return r}function G(e,t,r,a,n,o,i,s,l,d){let c=l?Object.values(l)[0]:s?Object.values(s)[0]:null,u=J(t,l?Object.keys(l)[0]:void 0).filter(((t,i)=>null!=t.route.loader&&(function(e,t,r){let a=!t||r.route.id!==t.route.id,n=void 0===e[r.route.id];return a||n}(e.loaderData,e.matches[i],t)||o.some((e=>e===t.route.id))||X(e.location,e.matches[i],r,a,t,n,c)))),h=[];return d&&d.forEach(((e,t)=>{let[a,o,s]=e;if(i.includes(t))h.push([t,a,o,s]);else if(n){X(a,o,r,a,o,n,c)&&h.push([t,a,o,s])}})),[u,h]}function V(e,t){let r=e.route.path;return e.pathname!==t.pathname||r&&r.endsWith("*")&&e.params["*"]!==t.params["*"]}function X(e,r,a,n,o,i,s){let l=c(e),d=r.params,u=c(n),h=o.params,f=V(r,o)||l.toString()===u.toString()||l.search!==u.search||i;if(o.route.shouldRevalidate){let e=o.route.shouldRevalidate(t({currentUrl:l,currentParams:d,nextUrl:u,nextParams:h},a,{actionResult:s,defaultShouldRevalidate:f}));if("boolean"==typeof e)return e}return f}async function Q(e,t,r,a,o,i,s,d){let c,u,f;void 0===o&&(o="/"),void 0===i&&(i=!1),void 0===s&&(s=!1);let p=new Promise(((e,t)=>f=t)),m=()=>f();t.signal.addEventListener("abort",m);try{let a=r.route[e];n(a,"Could not find the "+e+' to run on the "'+r.route.id+'" route'),u=await Promise.race([a({request:t,params:r.params,context:d}),p]),n(void 0!==u,"You defined "+("action"===e?"an action":"a loader")+' for route "'+r.route.id+"\" but didn't return anything from your `"+e+"` function. Please return a value or `null`.")}catch(e){c=h.error,u=e}finally{t.signal.removeEventListener("abort",m)}if(he(u)){let e,d=u.status;if(N.has(d)){let e=u.headers.get("Location");if(n(e,"Redirects returned/thrown from loaders/actions must have a Location header"),!(/^[a-z+]+:\/\//i.test(e)||e.startsWith("//"))){let i=S(e,C(a.slice(0,a.indexOf(r)+1)).map((e=>e.pathnameBase)),new URL(t.url).pathname);if(n(l(i),"Unable to resolve redirect location: "+e),o){let e=i.pathname;i.pathname="/"===e?o:x([o,e])}e=l(i)}if(i)throw u.headers.set("Location",e),u;return{type:h.redirect,status:d,location:e,revalidate:null!==u.headers.get("X-Remix-Revalidate")}}if(s)throw{type:c||h.data,response:u};let f=u.headers.get("Content-Type");return e=f&&f.startsWith("application/json")?await u.json():await u.text(),c===h.error?{type:c,error:new q(d,u.statusText,e),headers:u.headers}:{type:h.data,data:e,statusCode:u.status,headers:u.headers}}return c===h.error?{type:c,error:u}:u instanceof O?{type:h.deferred,deferredData:u}:{type:h.data,data:u}}function Z(e,t,r){let a=c(le(e)).toString(),n={signal:t};if(r&&me(r.formMethod)){let{formMethod:e,formEncType:t,formData:a}=r;n.method=e.toUpperCase(),n.body="application/x-www-form-urlencoded"===t?ee(a):a}return new Request(a,n)}function ee(e){let t=new URLSearchParams;for(let[r,a]of e.entries())n("string"==typeof a,'File inputs are not supported with encType "application/x-www-form-urlencoded", please use "multipart/form-data" instead.'),t.append(r,a);return t}function te(e,t,r,a,o){let i,s={},l=null,d=!1,c={};return r.forEach(((r,u)=>{let h=t[u].route.id;if(n(!ue(r),"Cannot handle redirect results in processLoaderData"),ce(r)){let t=ne(e,h),n=r.error;a&&(n=Object.values(a)[0],a=void 0),l=l||{},null==l[t.route.id]&&(l[t.route.id]=n),d||(d=!0,i=_(r.error)?r.error.status:500),r.headers&&(c[h]=r.headers)}else de(r)?(o&&o.set(h,r.deferredData),s[h]=r.deferredData.data):(s[h]=r.data,null==r.statusCode||200===r.statusCode||d||(i=r.statusCode),r.headers&&(c[h]=r.headers))})),a&&(l=a),{loaderData:s,errors:l,statusCode:i||200,loaderHeaders:c}}function re(e,r,a,o,i,s,l,d){let{loaderData:c,errors:u}=te(r,a,o,i,d);for(let r=0;r<s.length;r++){let[a,,o]=s[r];n(void 0!==l&&void 0!==l[r],"Did not find corresponding fetcher result");let i=l[r];if(ce(i)){let r=ne(e.matches,o.route.id);u&&u[r.route.id]||(u=t({},u,{[r.route.id]:i.error})),e.fetchers.delete(a)}else{if(ue(i))throw new Error("Unhandled fetcher revalidation redirect");if(de(i))throw new Error("Unhandled fetcher deferred data");{let t={state:"idle",data:i.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};e.fetchers.set(a,t)}}}return{loaderData:c,errors:u}}function ae(e,r,a){let n=t({},r);return a.forEach((t=>{let a=t.route.id;void 0===r[a]&&void 0!==e[a]&&(n[a]=e[a])})),n}function ne(e,t){return(t?e.slice(0,e.findIndex((e=>e.route.id===t))+1):[...e]).reverse().find((e=>!0===e.route.hasErrorBoundary))||e[0]}function oe(e){let t=e.find((e=>e.index||!e.path||"/"===e.path))||{id:"__shim-error-route__"};return{matches:[{params:{},pathname:"",pathnameBase:"",route:t}],route:t}}function ie(e,t){let{pathname:r,routeId:a,method:n}=void 0===t?{}:t,o="Unknown Server Error",i="Unknown @remix-run/router error";return 400===e?(o="Bad Request",i=n&&r&&a?"You made a "+n+' request to "'+r+'" but did not provide a `loader` for route "'+a+'", so there is no way to handle the request.':"Cannot submit binary form data using GET"):403===e?(o="Forbidden",i='Route "'+a+'" does not match URL "'+r+'"'):404===e?(o="Not Found",i='No route matches URL "'+r+'"'):405===e&&(o="Method Not Allowed",n&&r&&a?i="You made a "+n.toUpperCase()+' request to "'+r+'" but did not provide an `action` for route "'+a+'", so there is no way to handle the request.':n&&(i='Invalid request method "'+n.toUpperCase()+'"')),new q(e||500,o,new Error(i),!0)}function se(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if(ue(r))return r}}function le(e){return l(t({},"string"==typeof e?d(e):e,{hash:""}))}function de(e){return e.type===h.deferred}function ce(e){return e.type===h.error}function ue(e){return(e&&e.type)===h.redirect}function he(e){return null!=e&&"number"==typeof e.status&&"string"==typeof e.statusText&&"object"==typeof e.headers&&void 0!==e.body}function fe(e){if(!he(e))return!1;let t=e.status,r=e.headers.get("Location");return t>=300&&t<=399&&null!=r}function pe(e){return $.has(e)}function me(e){return W.has(e)}async function ge(e,t,r,a,n,o){for(let i=0;i<r.length;i++){let s=r[i],l=t[i],d=e.find((e=>e.route.id===l.route.id)),c=null!=d&&!V(d,l)&&void 0!==(o&&o[l.route.id]);de(s)&&(n||c)&&await ve(s,a,n).then((e=>{e&&(r[i]=e||r[i])}))}}async function ve(e,t,r){if(void 0===r&&(r=!1),!await e.deferredData.resolveData(t)){if(r)try{return{type:h.data,data:e.deferredData.unwrappedData}}catch(e){return{type:h.error,error:e}}return{type:h.data,data:e.deferredData.data}}}function ye(e){return new URLSearchParams(e).getAll("index").some((e=>""===e))}function we(e,t){let{route:r,pathname:a,params:n}=e;return{id:r.id,pathname:a,params:n,data:t[r.id],handle:r.handle}}function be(e,t){let r="string"==typeof t?d(t).search:t.search;if(e[e.length-1].route.index&&ye(r||""))return e[e.length-1];let a=C(e);return a[a.length-1]}e.AbortedDeferredError=U,e.ErrorResponse=q,e.IDLE_FETCHER=z,e.IDLE_NAVIGATION=F,e.UNSAFE_convertRoutesToDataRoutes=f,e.UNSAFE_getPathContributingMatches=C,e.createBrowserHistory=function(e){return void 0===e&&(e={}),u((function(e,t){let{pathname:r,search:a,hash:n}=e.location;return s("",{pathname:r,search:a,hash:n},t.state&&t.state.usr||null,t.state&&t.state.key||"default")}),(function(e,t){return"string"==typeof t?t:l(t)}),null,e)},e.createHashHistory=function(e){return void 0===e&&(e={}),u((function(e,t){let{pathname:r="/",search:a="",hash:n=""}=d(e.location.hash.substr(1));return s("",{pathname:r,search:a,hash:n},t.state&&t.state.usr||null,t.state&&t.state.key||"default")}),(function(e,t){let r=e.document.querySelector("base"),a="";if(r&&r.getAttribute("href")){let t=e.location.href,r=t.indexOf("#");a=-1===r?t:t.slice(0,r)}return a+"#"+("string"==typeof t?t:l(t))}),(function(e,t){o("/"===e.pathname.charAt(0),"relative pathnames are not supported in hash history.push("+JSON.stringify(t)+")")}),e)},e.createMemoryHistory=function(t){void 0===t&&(t={});let r,{initialEntries:a=["/"],initialIndex:n,v5Compat:i=!1}=t;r=a.map(((e,t)=>m(e,"string"==typeof e?null:e.state,0===t?"default":void 0)));let c=f(null==n?r.length-1:n),u=e.Action.Pop,h=null;function f(e){return Math.min(Math.max(e,0),r.length-1)}function p(){return r[c]}function m(e,t,a){void 0===t&&(t=null);let n=s(r?p().pathname:"/",e,t,a);return o("/"===n.pathname.charAt(0),"relative pathnames are not supported in memory history: "+JSON.stringify(e)),n}return{get index(){return c},get action(){return u},get location(){return p()},createHref:e=>"string"==typeof e?e:l(e),encodeLocation(e){let t="string"==typeof e?d(e):e;return{pathname:t.pathname||"",search:t.search||"",hash:t.hash||""}},push(t,a){u=e.Action.Push;let n=m(t,a);c+=1,r.splice(c,r.length,n),i&&h&&h({action:u,location:n})},replace(t,a){u=e.Action.Replace;let n=m(t,a);r[c]=n,i&&h&&h({action:u,location:n})},go(t){u=e.Action.Pop,c=f(c+t),h&&h({action:u,location:p()})},listen:e=>(h=e,()=>{h=null})}},e.createPath=l,e.createRouter=function(r){n(r.routes.length>0,"You must provide a non-empty routes array to createRouter");let a=f(r.routes),o=null,i=new Set,l=null,d=null,u=null,m=!1,g=p(a,r.history.location,r.basename),v=null;if(null==g){let e=ie(404,{pathname:r.history.location.pathname}),{matches:t,route:n}=oe(a);g=t,v={[n.id]:e}}let y,w,b=!g.some((e=>e.route.loader))||null!=r.hydrationData,D={historyAction:r.history.action,location:r.history.location,matches:g,initialized:b,navigation:F,restoreScrollPosition:null,preventScrollReset:!1,revalidation:"idle",loaderData:r.hydrationData&&r.hydrationData.loaderData||{},actionData:r.hydrationData&&r.hydrationData.actionData||null,errors:r.hydrationData&&r.hydrationData.errors||v,fetchers:new Map},E=e.Action.Pop,R=!1,A=!1,P=!1,M=[],C=[],S=new Map,x=0,L=-1,T=new Map,j=new Set,U=new Map,O=new Map;function H(e){D=t({},D,e),i.forEach((e=>e(D)))}function q(a,n){var o;H(t({},null!=D.actionData&&null!=D.navigation.formMethod&&"loading"===D.navigation.state&&(null==(o=D.navigation.formAction)?void 0:o.split("?")[0])===a.pathname?{}:{actionData:null},n,n.loaderData?{loaderData:ae(D.loaderData,n.loaderData,n.matches||[])}:{},{historyAction:E,location:a,initialized:!0,navigation:F,revalidation:"idle",restoreScrollPosition:!D.navigation.formData&&le(a,n.matches||D.matches),preventScrollReset:R})),A||E===e.Action.Pop||(E===e.Action.Push?r.history.push(a,a.state):E===e.Action.Replace&&r.history.replace(a,a.state)),E=e.Action.Pop,R=!1,A=!1,P=!1,M=[],C=[]}async function _(o,i,s){w&&w.abort(),w=null,E=o,A=!0===(s&&s.startUninterruptedRevalidation),function(e,t){if(l&&d&&u){let r=t.map((e=>we(e,D.loaderData))),a=d(e,r)||e.key;l[a]=u()}}(D.location,D.matches),R=!0===(s&&s.preventScrollReset);let c=s&&s.overrideNavigation,f=p(a,i,r.basename);if(!f){let e=ie(404,{pathname:i.pathname}),{matches:t,route:r}=oe(a);return te(),void q(i,{matches:t,loaderData:{},errors:{[r.id]:e}})}if(m=D.location,g=i,m.pathname===g.pathname&&m.search===g.search&&m.hash!==g.hash)return void q(i,{matches:f});var m,g;w=new AbortController;let v,b,T=Z(i,w.signal,s&&s.submission);if(s&&s.pendingError)b={[ne(f).route.id]:s.pendingError};else if(s&&s.submission&&me(s.submission.formMethod)){let r=await async function(r,a,n,o,i){let s;$(),H({navigation:t({state:"submitting",location:a},n)});let l=be(o,a);if(l.route.action){if(s=await Q("action",r,l,o,y.basename),r.signal.aborted)return{shortCircuited:!0}}else s={type:h.error,error:ie(405,{method:r.method,pathname:a.pathname,routeId:l.route.id})};if(ue(s))return await W(D,s,i&&!0===i.replace),{shortCircuited:!0};if(ce(s)){let t=ne(o,l.route.id);return!0!==(i&&i.replace)&&(E=e.Action.Push),{pendingActionError:{[t.route.id]:s.error}}}if(de(s))throw new Error("defer() is not supported in actions");return{pendingActionData:{[l.route.id]:s.data}}}(T,i,s.submission,f,{replace:s.replace});if(r.shortCircuited)return;v=r.pendingActionData,b=r.pendingActionError,c=t({state:"loading",location:i},s.submission),T=new Request(T.url,{signal:T.signal})}let{shortCircuited:_,loaderData:I,errors:N}=await async function(e,r,a,o,i,s,l,d){let c=o;if(!c){c=t({state:"loading",location:r,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},i)}let[u,h]=G(D,a,i,r,P,M,C,l,d,U);if(te((e=>!(a&&a.some((t=>t.route.id===e)))||u&&u.some((t=>t.route.id===e)))),0===u.length&&0===h.length)return q(r,{matches:a,loaderData:ae(D.loaderData,{},a),errors:d||null,actionData:l||null}),{shortCircuited:!0};A||(h.forEach((e=>{let[t]=e,r=D.fetchers.get(t),a={state:"loading",data:r&&r.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};D.fetchers.set(t,a)})),H(t({navigation:c,actionData:l||D.actionData||null},h.length>0?{fetchers:new Map(D.fetchers)}:{})));L=++x,h.forEach((e=>{let[t]=e;return S.set(t,w)}));let{results:f,loaderResults:p,fetcherResults:m}=await k(D.matches,a,u,h,e);if(e.signal.aborted)return{shortCircuited:!0};h.forEach((e=>{let[t]=e;return S.delete(t)}));let g=se(f);if(g)return await W(D,g,s),{shortCircuited:!0};let{loaderData:v,errors:y}=re(D,a,u,p,d,h,m,O);O.forEach(((e,t)=>{e.subscribe((r=>{(r||e.done)&&O.delete(t)}))})),function(){let e=[];for(let t of j){let r=D.fetchers.get(t);n(r,"Expected fetcher: "+t),"loading"===r.state&&(j.delete(t),e.push(t))}X(e)}();let b=ee(L);return t({loaderData:v,errors:y},b||h.length>0?{fetchers:new Map(D.fetchers)}:{})}(T,i,f,c,s&&s.submission,s&&s.replace,v,b);_||(w=null,q(i,{matches:f,loaderData:I,errors:N}))}function I(e){return D.fetchers.get(e)||z}async function W(t,r,a){var o;r.revalidate&&(P=!0);let i=s(t.location,r.location);if(n(i,"Expected a location on the redirect navigation"),void 0!==(null==(o=window)?void 0:o.location)){let e=c(r.location).origin;if(window.location.origin!==e)return void(a?window.location.replace(r.location):window.location.assign(r.location))}w=null;let l=!0===a?e.Action.Replace:e.Action.Push,{formMethod:d,formAction:u,formEncType:h,formData:f}=t.navigation;B.has(r.status)&&d&&me(d)&&h&&f?await _(l,i,{submission:{formMethod:d,formAction:r.location,formEncType:h,formData:f}}):await _(l,i,{overrideNavigation:{state:"loading",location:i,formMethod:d||void 0,formAction:u||void 0,formEncType:h||void 0,formData:f||void 0}})}async function k(e,t,r,a,n){let o=await Promise.all([...r.map((e=>Q("loader",n,e,t,y.basename))),...a.map((e=>{let[,t,r,a]=e;return Q("loader",Z(t,n.signal),r,a,y.basename)}))]),i=o.slice(0,r.length),s=o.slice(r.length);return await Promise.all([ge(e,r,i,n.signal,!1,D.loaderData),ge(e,a.map((e=>{let[,,t]=e;return t})),s,n.signal,!0)]),{results:o,loaderResults:i,fetcherResults:s}}function $(){P=!0,M.push(...te()),U.forEach(((e,t)=>{S.has(t)&&(C.push(t),V(t))}))}function N(e,t,r){let a=ne(D.matches,t);J(e),H({errors:{[a.route.id]:r},fetchers:new Map(D.fetchers)})}function J(e){S.has(e)&&V(e),U.delete(e),T.delete(e),j.delete(e),D.fetchers.delete(e)}function V(e){let t=S.get(e);n(t,"Expected fetch controller: "+e),t.abort(),S.delete(e)}function X(e){for(let t of e){let e={state:"idle",data:I(t).data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};D.fetchers.set(t,e)}}function ee(e){let t=[];for(let[r,a]of T)if(a<e){let e=D.fetchers.get(r);n(e,"Expected fetcher: "+r),"loading"===e.state&&(V(r),T.delete(r),t.push(r))}return X(t),t.length>0}function te(e){let t=[];return O.forEach(((r,a)=>{e&&!e(a)||(r.cancel(),t.push(a),O.delete(a))})),t}function le(e,t){if(l&&d&&u){let r=t.map((e=>we(e,D.loaderData))),a=d(e,r)||e.key,n=l[a];if("number"==typeof n)return n}return null}return y={get basename(){return r.basename},get state(){return D},get routes(){return a},initialize:function(){return o=r.history.listen((e=>{let{action:t,location:r}=e;return _(t,r)})),D.initialized||_(e.Action.Pop,D.location),y},subscribe:function(e){return i.add(e),()=>i.delete(e)},enableScrollRestoration:function(e,t,r){if(l=e,u=t,d=r||(e=>e.key),!m&&D.navigation===F){m=!0;let e=le(D.location,D.matches);null!=e&&H({restoreScrollPosition:e})}return()=>{l=null,u=null,d=null}},navigate:async function(a,n){if("number"==typeof a)return void r.history.go(a);let{path:o,submission:i,error:l}=Y(a,n),d=s(D.location,o,n&&n.state);d=t({},d,r.history.encodeLocation(d));let c=!0===(n&&n.replace)||null!=i&&me(i.formMethod)?e.Action.Replace:e.Action.Push,u=n&&"preventScrollReset"in n?!0===n.preventScrollReset:void 0;return await _(c,d,{submission:i,pendingError:l,preventScrollReset:u,replace:n&&n.replace})},fetch:function(e,o,i,s){if(K)throw new Error("router.fetch() was called during the server render, but it shouldn't be. You are likely calling a useFetcher() method in the body of your component. Try moving it to a useEffect or a callback.");S.has(e)&&V(e);let l=p(a,i,r.basename);if(!l)return void N(e,o,ie(404,{pathname:i}));let{path:d,submission:c}=Y(i,s,!0),u=be(l,d);c&&me(c.formMethod)?async function(e,o,i,s,l,d){if($(),U.delete(e),!s.route.action){let t=ie(405,{method:d.formMethod,pathname:i,routeId:o});return void N(e,o,t)}let c=D.fetchers.get(e),u=t({state:"submitting"},d,{data:c&&c.data});D.fetchers.set(e,u),H({fetchers:new Map(D.fetchers)});let h=new AbortController,f=Z(i,h.signal,d);S.set(e,h);let m=await Q("action",f,s,l,y.basename);if(f.signal.aborted)return void(S.get(e)===h&&S.delete(e));if(ue(m)){S.delete(e),j.add(e);let r=t({state:"loading"},d,{data:void 0});return D.fetchers.set(e,r),H({fetchers:new Map(D.fetchers)}),W(D,m)}if(ce(m))return void N(e,o,m.error);de(m)&&n(!1,"defer() is not supported in actions");let g=D.navigation.location||D.location,v=Z(g,h.signal),b="idle"!==D.navigation.state?p(a,D.navigation.location,r.basename):D.matches;n(b,"Didn't find any matches after fetcher action");let R=++x;T.set(e,R);let A=t({state:"loading",data:m.data},d);D.fetchers.set(e,A);let[_,I]=G(D,b,d,g,P,M,C,{[s.route.id]:m.data},void 0,U);I.filter((t=>{let[r]=t;return r!==e})).forEach((e=>{let[t]=e,r=D.fetchers.get(t),a={state:"loading",data:r&&r.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};D.fetchers.set(t,a),S.set(t,h)})),H({fetchers:new Map(D.fetchers)});let{results:B,loaderResults:F,fetcherResults:z}=await k(D.matches,b,_,I,v);if(h.signal.aborted)return;T.delete(e),S.delete(e),I.forEach((e=>{let[t]=e;return S.delete(t)}));let K=se(B);if(K)return W(D,K);let{loaderData:Y,errors:J}=re(D,D.matches,_,F,void 0,I,z,O),V={state:"idle",data:m.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};D.fetchers.set(e,V);let X=ee(R);"loading"===D.navigation.state&&R>L?(n(E,"Expected pending action"),w&&w.abort(),q(D.navigation.location,{matches:b,loaderData:Y,errors:J,fetchers:new Map(D.fetchers)})):(H(t({errors:J,loaderData:ae(D.loaderData,Y,b)},X?{fetchers:new Map(D.fetchers)}:{})),P=!1)}(e,o,d,u,l,c):(U.set(e,[d,u,l]),async function(e,r,a,o,i,s){let l=D.fetchers.get(e),d=t({state:"loading",formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},s,{data:l&&l.data});D.fetchers.set(e,d),H({fetchers:new Map(D.fetchers)});let c=new AbortController,u=Z(a,c.signal);S.set(e,c);let h=await Q("loader",u,o,i,y.basename);de(h)&&(h=await ve(h,u.signal,!0)||h);S.get(e)===c&&S.delete(e);if(u.signal.aborted)return;if(ue(h))return void await W(D,h);if(ce(h)){let t=ne(D.matches,r);return D.fetchers.delete(e),void H({fetchers:new Map(D.fetchers),errors:{[t.route.id]:h.error}})}n(!de(h),"Unhandled fetcher deferred data");let f={state:"idle",data:h.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};D.fetchers.set(e,f),H({fetchers:new Map(D.fetchers)})}(e,o,d,u,l,c))},revalidate:function(){$(),H({revalidation:"loading"}),"submitting"!==D.navigation.state&&("idle"!==D.navigation.state?_(E||D.historyAction,D.navigation.location,{overrideNavigation:D.navigation}):_(D.historyAction,D.location,{startUninterruptedRevalidation:!0}))},createHref:e=>r.history.createHref(e),encodeLocation:e=>r.history.encodeLocation(e),getFetcher:I,deleteFetcher:J,dispose:function(){o&&o(),i.clear(),w&&w.abort(),D.fetchers.forEach(((e,t)=>J(t)))},_internalFetchControllers:S,_internalActiveDeferreds:O},y},e.defer=function(e){return new O(e)},e.generatePath=function(e,t){void 0===t&&(t={});let r=e;return r.endsWith("*")&&"*"!==r&&!r.endsWith("/*")&&(A(!1,'Route path "'+r+'" will be treated as if it were "'+r.replace(/\*$/,"/*")+'" because the `*` character must always follow a `/` in the pattern. To get rid of this warning, please change the route path to "'+r.replace(/\*$/,"/*")+'".'),r=r.replace(/\*$/,"/*")),r.replace(/^:(\w+)/g,((e,r)=>(n(null!=t[r],'Missing ":'+r+'" param'),t[r]))).replace(/\/:(\w+)/g,((e,r)=>(n(null!=t[r],'Missing ":'+r+'" param'),"/"+t[r]))).replace(/(\/?)\*/,((e,r,a,n)=>null==t["*"]?"/*"===n?"/":"":""+r+t["*"]))},e.getStaticContextFromError=function(e,r,a){return t({},r,{statusCode:500,errors:{[r._deepestRenderedBoundaryId||e[0].id]:a}})},e.getToPathname=function(e){return""===e||""===e.pathname?"/":"string"==typeof e?d(e).pathname:e.pathname},e.invariant=n,e.isRouteErrorResponse=_,e.joinPaths=x,e.json=function(e,r){void 0===r&&(r={});let a="number"==typeof r?{status:r}:r,n=new Headers(a.headers);return n.has("Content-Type")||n.set("Content-Type","application/json; charset=utf-8"),new Response(JSON.stringify(e),t({},a,{headers:n}))},e.matchPath=D,e.matchRoutes=p,e.normalizePathname=L,e.parsePath=d,e.redirect=function(e,r){void 0===r&&(r=302);let a=r;"number"==typeof a?a={status:a}:void 0===a.status&&(a.status=302);let n=new Headers(a.headers);return n.set("Location",e),new Response(null,t({},a,{headers:n}))},e.resolvePath=P,e.resolveTo=S,e.stripBasename=R,e.unstable_createStaticHandler=function(e,r){n(e.length>0,"You must provide a non-empty routes array to unstable_createStaticHandler");let a=f(e),o=(r?r.basename:null)||"/";async function i(e,r,a,i,s){n(e.signal,"query()/queryRoute() requests must contain an AbortController signal");try{if(me(e.method.toLowerCase())){let n=await async function(e,r,a,n,i){let s;if(a.route.action){if(s=await Q("action",e,a,r,o,!0,i,n),e.signal.aborted){throw new Error((i?"queryRoute":"query")+"() call aborted")}}else{let t=ie(405,{method:e.method,pathname:new URL(e.url).pathname,routeId:a.route.id});if(i)throw t;s={type:h.error,error:t}}if(ue(s))throw new Response(null,{status:s.status,headers:{Location:s.location}});if(de(s))throw new Error("defer() is not supported in actions");if(i){if(ce(s))throw s.error;return{matches:[a],loaderData:{},actionData:{[a.route.id]:s.data},errors:null,statusCode:200,loaderHeaders:{},actionHeaders:{}}}if(ce(s)){let o=ne(r,a.route.id);return t({},await d(e,r,n,void 0,{[o.route.id]:s.error}),{statusCode:_(s.error)?s.error.status:500,actionData:null,actionHeaders:t({},s.headers?{[a.route.id]:s.headers}:{})})}let l=new Request(e.url,{headers:e.headers,redirect:e.redirect,signal:e.signal});return t({},await d(l,r,n),s.statusCode?{statusCode:s.statusCode}:{},{actionData:{[a.route.id]:s.data},actionHeaders:t({},s.headers?{[a.route.id]:s.headers}:{})})}(e,a,s||be(a,r),i,null!=s);return n}let n=await d(e,a,i,s);return he(n)?n:t({},n,{actionData:null,actionHeaders:{}})}catch(e){if((l=e)&&he(l.response)&&(l.type===h.data||h.error)){if(e.type===h.error&&!fe(e.response))throw e.response;return e.response}if(fe(e))return e;throw e}var l}async function d(e,r,a,n,i){let s=null!=n;if(s&&(null==n||!n.route.loader))throw ie(400,{method:e.method,pathname:new URL(e.url).pathname,routeId:null==n?void 0:n.route.id});let l=(n?[n]:J(r,Object.keys(i||{})[0])).filter((e=>e.route.loader));if(0===l.length)return{matches:r,loaderData:{},errors:i||null,statusCode:200,loaderHeaders:{}};let d=await Promise.all([...l.map((t=>Q("loader",e,t,r,o,!0,s,a)))]);if(e.signal.aborted){throw new Error((s?"queryRoute":"query")+"() call aborted")}return d.forEach((e=>{de(e)&&e.deferredData.cancel()})),t({},te(r,l,d,i),{matches:r})}return{dataRoutes:a,query:async function(e,r){let{requestContext:n}=void 0===r?{}:r,d=new URL(e.url),c=e.method.toLowerCase(),u=s("",l(d),null,"default"),h=p(a,u,o);if(!pe(c)&&"head"!==c){let e=ie(405,{method:c}),{matches:t,route:r}=oe(a);return{basename:o,location:u,matches:t,loaderData:{},actionData:null,errors:{[r.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{}}}if(!h){let e=ie(404,{pathname:u.pathname}),{matches:t,route:r}=oe(a);return{basename:o,location:u,matches:t,loaderData:{},actionData:null,errors:{[r.id]:e},statusCode:e.status,loaderHeaders:{},actionHeaders:{}}}let f=await i(e,u,h,n);return he(f)?f:t({location:u,basename:o},f)},queryRoute:async function(e,t){let{routeId:r,requestContext:n}=void 0===t?{}:t,d=new URL(e.url),c=e.method.toLowerCase(),u=s("",l(d),null,"default"),h=p(a,u,o);if(!pe(c)&&"head"!==c)throw ie(405,{method:c});if(!h)throw ie(404,{pathname:u.pathname});let f=r?h.find((e=>e.route.id===r)):be(h,u);if(r&&!f)throw ie(403,{pathname:u.pathname,routeId:r});if(!f)throw ie(404,{pathname:u.pathname});let m=await i(e,u,h,n,f);if(he(m))return m;let g=m.errors?Object.values(m.errors)[0]:void 0;if(void 0!==g)throw g;let v=[m.actionData,m.loaderData].find((e=>e));return Object.values(v||{})[0]}}},e.warning=A,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=router.umd.min.js.map
